# Contributor: Grigory Kirillov <txgk@bk.ru>
# Maintainer:
pkgname=yyjson
pkgver=0.8.0
pkgrel=0
pkgdesc="High performance JSON library written in ANSI C"
url="https://github.com/ibireme/yyjson"
arch="all"
license="MIT"
makedepends="cmake samurai"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc"
source="https://github.com/ibireme/yyjson/archive/$pkgver/yyjson-$pkgver.tar.gz"

build() {
	cmake -B builddir -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DBUILD_SHARED_LIBS=ON \
		-DYYJSON_BUILD_TESTS="$(want_check && echo ON || echo OFF)"
	cmake -B builddir-static -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=MinSizeRel
	cmake --build builddir
	cmake --build builddir-static
}

check() {
	ctest --output-on-failure --test-dir builddir
}

package() {
	DESTDIR="$pkgdir" cmake --install builddir
	DESTDIR="$pkgdir" cmake --install builddir-static
	for file in README.md doc/API.md doc/BuildAndTest.md doc/DataStructure.md; do
		install -Dm644 "$file" -t "$pkgdir"/usr/share/doc/"$pkgname"
	done
}

sha512sums="
3872b46930fd0f4d659004a4d08cdb1c506ccc2bf2888f5ee50523929a2b72f9d8e72ee71dc958ebca630f1886858d4350521bffc18c300a27d25436833384a9  yyjson-0.8.0.tar.gz
"
